home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / pmode / 386p_200 / sb_xsd.asm < prev    next >
Encoding:
Assembly Source File  |  1995-01-13  |  6.3 KB  |  298 lines

  1. .386P
  2. ; DO NOT USE IT, I JUST STARTED CODING, LOTS OF THINGS ARE MISSING!!
  3.  
  4. code32  segment para public use32
  5.         assume cs:code32, ds:code32
  6.  
  7. include 386power.inc
  8. include vdma.inc
  9. include 386timer.inc
  10.  
  11. ; XVD SOUNDBLASTER DRIVER
  12. sb_base dd 0
  13. sb_irqn dd 7
  14. sb_dmac dd 1
  15. sb_type dd 0
  16.  
  17. ; some useful i/o port offsets from sb_base
  18. dsp_reset dd  6
  19. sb_fm     dd  8
  20. sb_fmdata dd  9
  21. dsp_read  dd 0ah
  22. dsp_write dd 0ch
  23. dsp_avail dd 0eh
  24.  
  25. ; dsp commands
  26. dma8_dac      =  14h
  27. time_constant =  40h
  28. halt_dma      = 0d0h
  29. cont_dma      = 0d4h
  30. speaker_on    = 0d1h
  31. speaker_off   = 0d3h
  32. dsp_id        = 0e0h
  33. dsp_ver       = 0e1h
  34.  
  35. ; sb_types
  36. sb_1_5 =1
  37. sbpro  =2
  38. sb_2_0 =3
  39.  
  40. sbwrite: ; in: ah = byte to write to dsp   , out: eax,edx modified
  41.         mov edx,dsp_write
  42. sbw:    in al,dx
  43.         test al,080h
  44.         jnz sbw
  45.         mov al,ah
  46.         out dx,ax
  47.         ret
  48.  
  49. sbread: ; edx modified   out: al = byte read from dsp
  50.         mov edx,dsp_avail
  51. sbr:    in al,dx
  52.         test al,80h
  53.         jz sbr
  54.         sub dl,4
  55.         in al,dx
  56.         ret
  57.  
  58. ; DAC 8bit mono DMA allowed frequencies for a plain soundblaster
  59. ; 4khz ... 23khz
  60. ; you set the playback frequency sending a time_constant command
  61. ; and then sending the t_c byte equivalent to the requested frequency
  62. ;
  63. ; t_c = 256 - (1000000/frequency)
  64. ;
  65. ; then you need to calculate the actual playback frequency you set
  66. ; (there are rounding errors)
  67. ;
  68. ; actual_frequency = 1000000/(256 - t_c)
  69. ;
  70.  
  71. setfreq: ; in:  eax= requested frequency
  72.          ; out: eax= nearest supported frequency
  73.          push edx
  74.          push ebx
  75.          cmp eax,4000
  76.          jg goodlow
  77.          mov eax,4000
  78. goodlow: cmp eax,23000
  79.          jl goodhi
  80.          mov eax,23000
  81. goodhi:  xor edx,edx
  82.          mov ebx,eax
  83.          mov eax,1000000
  84.          div ebx
  85.          sub eax,256
  86.          neg eax
  87.          shl eax,16 ; save t_c into upper word
  88.          mov ah,time_constant
  89.          call sbwrite
  90.          shr eax,8 ; t_c into ah
  91.          call sbwrite
  92.          ; now get back the actual playback frequency
  93.          shr eax,8 ; eax == t_c
  94.          mov ebx,256
  95.          xor edx,edx
  96.          sub ebx,eax
  97.          mov eax,1000000
  98.          div ebx
  99.          ; eax = actual frequency
  100.          pop ebx
  101.          pop edx
  102.          ret
  103.  
  104. sbirq_ack macro
  105.           mov edx,dsp_avail
  106.           in al,dx
  107.           ; sb irq acknowledged , now notify the eoi to the P.I.C.
  108.           endm
  109.  
  110. sbsound   macro
  111.           mov ah,speaker_on
  112.           call sbwrite
  113.           endm
  114.  
  115. nosbsound macro
  116.           mov ah,speaker_off
  117.           call sbwrite
  118.           endm
  119.  
  120. no_blast db 'SoundBlaster XSD DRIVER: DSP timeout or 386Timer too fast',CR,LF
  121.          db '     Maybe soundblaster not present or wrong base address',CR,LF,'$'
  122.  
  123. error_no_blaster:
  124.         mov 386Return,offset no_blast
  125.         jmp _Exit
  126. ; reset sound blaster dsp
  127.  
  128. dspreset:
  129.          pushad
  130.          mov edx,dsp_reset
  131.          mov al,01
  132.          out dx,al
  133. recaliber:
  134.          call _ReadTimer
  135.          lea ebx,[eax+10]
  136.          cmp eax,ebx
  137.          jnb  recaliber
  138. skid3:   call _ReadTimer
  139.          cmp eax,ebx
  140.          jb skid3
  141.          mov edx,dsp_reset
  142.          xor al,al
  143.          out dx,al
  144. xrecaliber:
  145.          call _ReadTimer
  146.          lea ebx,[eax+400]
  147.          cmp eax,ebx
  148.          jnb  xrecaliber
  149. skid100: mov edx,dsp_read
  150.          in al,dx
  151.          cmp al,0AAh
  152.          je gotcha
  153.          call _ReadTimer
  154.          cmp eax,ebx
  155.          jb skid100
  156.          jmp error_no_blaster
  157. gotcha:  popad
  158.          ret
  159.  
  160. ; ENVIRONMENT SCANNER
  161. ;
  162. ; The environment segment is a sequence of ASCIIZ strings
  163. ; following the format "var=value",0
  164. ; and terminated by a null string (a single code 0 character)
  165.  
  166. ENV_SEG= 2ch
  167. SPACE=32
  168. TAB=9
  169.  
  170. envfind: ; in:  esi = ptr to ASCIIZ string containing the invironment var. name
  171.          ; out: esi = ptr to ASCIIZ string (by way of the 4GW wraparound)
  172.          ;            containing the environment var. "value"
  173.          ;            n.b. read it but do not modify it!!!!!!
  174.  
  175.         push edx
  176.         push ebx
  177.         push eax
  178.         mov edx,_PSPBase
  179.         add edx,ENV_SEG
  180.         movzx edx,word ptr gs:[edx]
  181.         shl edx,4
  182.         sub edx,_Code32Base
  183. estring:
  184.         mov ebx,esi
  185. eqchar: mov al,[edx]
  186.         cmp al,SPACE
  187.         je skiip
  188.         cmp al,TAB
  189.         je skiip
  190.         cmp al,[ebx]
  191.         jne naah
  192.         inc ebx
  193. skiip:
  194.         inc edx
  195.         jmp short eqchar
  196.  
  197. naah:   cmp al,'='
  198.         jne findend
  199.         cmp byte ptr [ebx],0
  200.         je cuccato
  201. findend:
  202.         cmp ebx,esi
  203.         je lafine
  204. z_end:  inc edx
  205.         test al,al
  206.         jz estring
  207.         mov al,[edx]
  208.         jmp short z_end
  209.  
  210. lafine: test al,al
  211.         jne z_end
  212. byenv:  mov esi,edx
  213.         pop eax
  214.         pop ebx
  215.         pop edx
  216. cuccato:
  217.         inc edx
  218.         jmp short byenv
  219.  
  220. ; get BLASTER environment var. settings
  221.  
  222. sb db 'BLASTER',0   ; ASCIIZ BLASTER
  223.  
  224. sbenv:  pushad
  225.         cmp sb_base,0
  226.         jne env_set
  227.         mov esi, offset sb
  228.         call envfind
  229. nextc:  lodsb
  230.         test al,al
  231.         jz settato
  232.         cmp al,SPACE
  233.         je nextc
  234.         cmp al,TAB
  235.         je nextc
  236.         cmp al,'I'
  237.         jne newa
  238.         lodsb
  239.         sub al,'0'
  240.         mov  byte ptr sb_irqn,al
  241.         jmp short nextc
  242. newa:
  243.         cmp al,'D'
  244.         jne newb
  245.         lodsb
  246.         sub al,'0'
  247.         mov  byte ptr sb_dmac,al
  248.         jmp short nextc
  249. newb:
  250.         cmp al,'T'
  251.         jne newc
  252.         lodsb
  253.         sub al,'0'
  254.         mov  byte ptr sb_type,al
  255.         jmp short nextc
  256. newc:
  257.         cmp al,'A'
  258.         jne nextc  ; try to ignore unknown switches
  259.         xor eax,eax
  260. sboing: lodsb
  261.         cmp al,'0'
  262.         jb sguuk
  263.         cmp al,'9'
  264.         ja sguuk
  265.         sub al,'0'
  266. skud:   shl al,4
  267.         shl eax,4
  268.         jmp short sboing
  269. sguuk:
  270.         cmp al,'a'
  271.         jb sgook
  272.         cmp al,'f'
  273.         ja sgook
  274.         sub al,'a'
  275.         jmp short skud
  276. sgook:
  277.         cmp al,'A'
  278.         jb sgok
  279.         cmp al,'F'
  280.         ja sgok
  281.         sub al,'A'
  282.         jmp short skud
  283. sgok:   shr eax,8
  284.         mov sb_base,eax
  285.         jmp short nextc
  286.  
  287. settato:
  288.         mov eax,sb_base
  289.         test eax,eax
  290.         jz wrong_set
  291.  
  292.  
  293.  
  294. env_set:
  295.         popad
  296.         ret
  297.  
  298.